﻿using UnityEngine;

namespace Assets.AnimationPlayer.Scripts.Util
{
    public class ArCat : MonoBehaviour
    {
        private float _mx;
        private Touch _oneTouch;
        internal void LateUpdate()
        {
            if (transform.gameObject.activeInHierarchy)
            {
                if (Input.touchCount == 1)
                {
                    _oneTouch = Input.touches[0];
                    if (_oneTouch.phase == TouchPhase.Moved)
                    {
                        if (Mathf.Abs(_oneTouch.deltaPosition.x) > Mathf.Abs(_oneTouch.deltaPosition.y))
                        {
                            if (_oneTouch.deltaPosition.x > 0)
                                _left();
                            else if (_oneTouch.deltaPosition.x < 0)
                                _right();
                        }
                    }
                }

                if (Input.GetMouseButton(0))
                {
                    if (Input.GetAxis("Mouse X") > 0)
                        _left();
                    else if (Input.GetAxis("Mouse X") < 0)
                        _right();
                }
            }
        }

        private void _left()
        {
            _mx = _mx -3.5f;
            Quaternion mRotation = Quaternion.Euler(0, _mx, 0);
            transform.localRotation = mRotation;
        }

        private void _right()
        {
            _mx = _mx +3.5f;
            Quaternion mRotation = Quaternion.Euler(0, _mx, 0);
            transform.localRotation = mRotation;
        }
    }
}